package com.server.questionbank.snframe.service.OllamaService.KnowledgeBaseService;


import com.server.questionbank.snframe.domain.Course.TCourse;
import com.server.questionbank.snframe.domain.User.TUser;
import com.server.questionbank.snframe.service.CourseService.TCourseService;
import com.server.questionbank.snframe.service.UsersService.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Configuration
public class KnowledgeDataBase {
    @Autowired
    private UsersService usersService;
    @Autowired
    private TCourseService tCourseService;

    // 获取数据库数据
    public Map<String, String> safeReadDatabase()
    {
        Map<String, String> knowledgeItems = new HashMap<>();

        // 添加用户数据
        knowledgeItems.put("users", getUsers());
        // 添加课程数据
        knowledgeItems.put("courses", getCourses());

        return knowledgeItems;
    }

    // 获取用户数据
    private String getUsers() {
        StringBuilder users = new StringBuilder();
        users.append("[用户表]\n");
        List<TUser> tUsers = usersService.selectAllUser();
        for (TUser tUser : tUsers) {
            users.append("用户ID：\"").append(tUser.getUserId()).append("\", ");
            users.append("手机号：\"").append(tUser.getPhoneNumber()).append("\", ");
            users.append("密码：\"").append(tUser.getPasswordHash()).append("\", ");
            users.append("用户名：\"").append(tUser.getUserName()).append("\", ");
            users.append("昵称：\"").append(tUser.getNickName()).append("\", ");
            users.append("头像：\"").append(tUser.getAvatar()).append("\", ");
            users.append("邮箱：\"").append(tUser.getUserEmail()).append("\", ");
            users.append("管理员：\"").append(tUser.getSupermanager()).append("\", ");
            users.append("注册时间：\"").append(tUser.getRegTime()).append("\", ");
            users.append("更新时间：\"").append(tUser.getUpdateTime()).append("\", ");
            users.append("更新人：\"").append(tUser.getUpdateBy()).append("\", ");
            users.append("简历：\"").append(tUser.getResume()).append("\". \n");
        }
        return users.toString();
    }

    // 获取课程数据
    private String getCourses() {
        StringBuilder courses = new StringBuilder();
        courses.append("[课程表]\n");
        List<TCourse> tCourses = tCourseService.getAllCourse();
        for (TCourse tCourse : tCourses) {
            courses.append("课程ID：\"").append(tCourse.getCourseId()).append("\", ");
            courses.append("课程名：\"").append(tCourse.getCourseName()).append("\", ");
            courses.append("课程难度：\"").append(tCourse.getCourseDifficultyId()).append("\", ");
//            courses.append("课程封面：\"").append(tCourse.getCoursePicFileId()).append("\", ");
            courses.append("课程描述：\"").append(tCourse.getCourseDescription()).append("\", ");
            courses.append("创建人：\"").append(tCourse.getCreateBy()).append("\", ");
            courses.append("创建时间：\"").append(tCourse.getCreateDate()).append("\". \n");
        }
        return courses.toString();
    }
}
